package ca.nfb.media.nfbPlayer.views
{
	import ca.nfb.media.nfbPlayer.ComModule;
	import ca.nfb.media.nfbPlayer.ui.Scroller;
	import ca.turbulent.text.SuperText;
	
	import flash.display.MovieClip;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;
	import flash.text.AntiAliasType;
	import flash.text.Font;
	import flash.text.GridFitType;
	import flash.text.StyleSheet;
	import flash.text.TextField;
	import flash.text.TextFormat;
	
	
	public class MoreInfo extends NFBPlayerView
	{
		
		private var title_txt		:TextField;
		private var text_txt		:TextField;
		public var endPlaylistOn	:Boolean = false;
		public var scroller			:Scroller;
		
		public var videoInfos		:Object = new Object();
		
		public function MoreInfo()
		{
			super();
		}
		
		override protected function checkLang():void
		{
			switch(ComModule.getLang())
			{
				case "EN":
				linkButton_mc.gotoAndStop(1);
				break;
				
				case "FR":
				linkButton_mc.gotoAndStop(2);
				break;
			}
		}
		
		override public function close(evt:*=null):void
		{
			this.visible = false;
			core.overlayedPanelOpen = false;
			
			if (this.previousState == NFBPlayer.PREVIEW_IMAGE_STATE)
			{
				core.setCurrentState(NFBPlayer.PREVIEW_IMAGE_STATE);
				if (core.embeddedMode)
					core.embeddedWelcomeView.show();	
				
				if (core.warningMessageView.wasShowing)
					core.warningMessageView.visible = true;	
					
				return;	
			}
			
			if (!core.wasPaused)
			{
				if (this.previousState != NFBPlayer.END_PLAYLIST_STATE)
				{
					player.play();
				}
			}	
			else
			{
				core.controlBar.overlay_mc.mouseEnabled = false;
				core.controlBar.overlay_mc.alpha = 0;	
			}
			core.wasPaused = false;
			
			if (this.endPlaylistOn)
			{
				endPlaylistOn = false;
				core.finalPlaylistView.wasDrawnEarlier = true;						
				core.setCurrentState(NFBPlayer.END_PLAYLIST_STATE);
			}
			else
			{
				core.finalPlaylistView.wasDrawnEarlier = false;
				core.setCurrentState(NFBPlayer.DEFAULT_STATE);
			}
		}
		
		override protected function addedToStage(evt:Event):void 
		{ 
			registerStageEvents();	
			this.x = this.y = 7;
			this.visible = false;
			
			MovieClip(closeButton_mc).useHandCursor = true;
			MovieClip(closeButton_mc).buttonMode = true;
			MovieClip(closeButton_mc).mouseEnabled = true;
			
			MovieClip(infosButton_mc).useHandCursor = true;
			MovieClip(infosButton_mc).buttonMode = true;
			MovieClip(infosButton_mc).mouseEnabled = true;
			
			MovieClip(linkButton_mc).useHandCursor = true;
			MovieClip(linkButton_mc).buttonMode = true;
			MovieClip(linkButton_mc).mouseEnabled = true;
			
			MovieClip(infosButton_mc).addEventListener(MouseEvent.CLICK, close, false, 0, true);
			MovieClip(closeButton_mc).addEventListener(MouseEvent.CLICK, close, false, 0, true);
			MovieClip(linkButton_mc).addEventListener(MouseEvent.CLICK, link, false, 0, true);
			MovieClip(linkButton_mc).addEventListener(MouseEvent.MOUSE_OVER, linkMOver, false, 0, true);
			MovieClip(linkButton_mc).addEventListener(MouseEvent.MOUSE_OUT, linkMOut, false, 0, true);
			title_txt = new TextField();
			title_txt.width = 400; 
			title_txt.height = 73; 
			title_txt.multiline = true;
			title_txt.selectable = false;
			title_txt.wordWrap = true;
			title_txt.embedFonts = true;
			title_txt.antiAliasType = AntiAliasType.ADVANCED;
			title_txt.gridFitType = GridFitType.PIXEL;
			title_txt.sharpness = 100;
			title_txt.thickness = 100;
			title_txt.textColor = 0xFFFFFF
			title_txt.x = 9;
			title_txt.y = 11;
			title_txt.defaultTextFormat = new TextFormat(Font(ComModule.getInstance().core.mainFont).fontName, 12, 0xffcc66);
			
			text_txt = new TextField();
			text_txt.width = 352;
			text_txt.height = 169;
			text_txt.multiline = true;
			text_txt.wordWrap = true;
			text_txt.embedFonts = true;
			text_txt.selectable = true;
			
			var styleSheet:StyleSheet = new  StyleSheet();
			var styleObj:Object = new Object(); 
			styleObj.fontFamily = Font(ComModule.getInstance().core.mainFont).fontName;
			styleObj.fontSize = 16;
			styleObj.color = "#FFFFFF"; 
			
			styleSheet.setStyle(".regText", styleObj); 
 			
 			text_txt.styleSheet = styleSheet;
 			
			
			
			
			var defTxtFormat:TextFormat = new TextFormat(Font(ComModule.getInstance().core.mainFont).fontName, 16, 0xFFFFFF);
			defTxtFormat.leading = 4;
			// text_txt.defaultTextFormat = defTxtFormat;
			text_txt.antiAliasType = AntiAliasType.ADVANCED;
			title_txt.gridFitType = GridFitType.PIXEL;
			text_txt.sharpness = 300;
			text_txt.thickness = -100;
			// text_txt.textColor = 0xFFFFFF;
			text_txt.x = 11;
			text_txt.y = 95;
			
			addChild(title_txt);
			addChild(text_txt);
			
			scroller = new Scroller(text_txt);
			scroller.x = 372.5;
			scroller.y = 88.5;
			scroller.visible = false;
			addChild(scroller);
			setTexts();
			
		}
		
		private function link(evt:MouseEvent):void
		{
			navigateToURL(new URLRequest(ComModule.getInstance().latestDirectURL), "_self");
		}
		
		private function linkMOver(evt:MouseEvent):void
		{
			linkButton_mc.label_mc.gotoAndStop(2);
		}
		
		private function linkMOut(evt:MouseEvent):void
		{
			linkButton_mc.label_mc.gotoAndStop(1);
		}
		
		override protected function coreStateUpdated(evt:Event=null):void 
		{
			
			if (core.currentState == NFBPlayer.MORE_INFOS_STATE)
			{
				if (core.embeddedMode)
				{
					core.overlayedPanelOpen = true;
					this.visible = true;
					if (ComModule.getInstance().latestDirectURL != "")
					{
						linkButton_mc.visible = true;
					}
					else
					{
						linkButton_mc.visible = false;
					}	
					
				}	
			}	
			else
			{
				this.visible = false;
			}
		}
		
		public function setTexts():void
		{
			videoInfos = ComModule.getInstance().currentMovieInfos;
			if (videoInfos.title.length > 0)
			{	
				title_txt.htmlText = videoInfos.title;
		
				var tf:TextFormat = new TextFormat(Font(ComModule.getInstance().core.mainFont).fontName, 21, 0xFFFFFF);
				title_txt.setTextFormat(tf, 0, String(videoInfos.title).length);
			}
			
	//		text_txt.htmlText = "<span class='regText'> éàÀéÉëöôêûioçç ediufhefi uehfieu f eifu heife <br> ededheidu ehidu hediuehdi eudheiud eflew lkeeelec<br><font size='21' color='#333322'> <a href='http://www.macromedia.com' target='_blank'> Go home</a> </> </font></span>";
			if (videoInfos.description.length > 0)
			{
				text_txt.htmlText = "<span class='regText'>"+videoInfos.description+"</span>";
				text_txt.scrollV = 0;
			
				core.screenReaderManager.addAccess(title_txt, title_txt.text, title_txt.text);
			}
			scroller.reset();
		}
		
		
	}
}